package com.mercenary.wein.screenControl.bean;

import com.google.common.base.Joiner;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.util.List;
import java.util.Map;

/**
 * Created by tuxiao on 2017/3/19.
 */
public class CommandDetailBean {
    private long id;
    private int actionId;
    private String dName;
    private String actionName;
    private String content;
    private String status;
    private String submit_time;
    private String exe_mode;

    public String getExe_mode() {
        return exe_mode;
    }

    public void setExe_mode(String exe_mode) {
        this.exe_mode = exe_mode;
    }

    public String getdName() {
        return dName;
    }

    public void setdName(String dName) {
        this.dName = dName;
    }

    public String getSubmit_time() {
        return submit_time;
    }

    public void setSubmit_time(String submit_time) {
        this.submit_time = submit_time;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public CommandDetailBean(int actionId, String content) {
        this.content = content;
        this.actionId = actionId;
    }

    public CommandDetailBean(long id, int actionId, String dName, String actionName, String content, String status, String submit_time) {
        this.id = id;
        this.actionId = actionId;
        this.dName = dName;
        this.actionName = actionName;
        this.content = content;
        this.status = status;
        this.submit_time = submit_time;
    }

    public CommandDetailBean(){

    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public int getActionId() {
        return actionId;
    }

    public void setActionId(int actionId) {
        this.actionId = actionId;
    }

    public String getActionName() {
        return actionName;
    }

    public void setActionName(String actionName) {
        this.actionName = actionName;
    }

    public String getContent() {
        return parseContent(content);
    }

    public void setContent(String content) {
        this.content = content;
    }


    private String parseContent(String content){
        String result ="";
        Map<String,Object> json = new Gson().fromJson(content,new TypeToken<Map<String,Object>>(){}.getType());
        if(!json.containsKey("action"))return "未知任务信息";
        String cid = json.get("action").toString().split("\\.")[0];
        if(!cid.matches("\\d+"))return "未知任务信息";
        int id = Integer.parseInt(cid);
        switch (id){
            case 1001 : {
                result = "共发送"+json.get("count").toString()+"张图片";
                break;
            }
            case 1025 : {
                result = "手机号列表："+ Joiner.on(",").join((List<String>)json.get("contacts"));
                break;
            }
        }
        return result;
    }
}
